package app.htby.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.alibaba.fastjson.JSON;

import app.entity.CtrlBean;
import app.entity.IOTPBean;
import app.entity.IOTPBody;

public class TestIotpBean {
	
	public static void main(String[] args) throws ParseException {
		
		/**
		 * IOTP协议的测试代码----转成byte数组
		 */
		IOTPBean iotp = new IOTPBean();
		iotp.setTag(0x1011);
		iotp.setType(0);
		iotp.setEnd(0x1213);
		iotp.setLicense("我是一个授权码");
		iotp.setSequence_id(123);
		iotp.setSequence_sub_id(456);
		iotp.setSource_id(789);
		iotp.setSource_type(111);
		iotp.setDate_time(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2018-05-18 00:00:00"));
		IOTPBody body = new IOTPBody();
		body.setSubtype(123);
		List<String> list = new ArrayList<String>();
		int index = 0;
		while(index < 1){
			CtrlBean cb = new CtrlBean();
			cb.setSendMsg("http://htby.com/1/2/3/4/5_2018-05-21 09:00:00_2018-05-21 09:05:00_5");
			cb.setId("aaadas1");
			list.add(JSON.toJSONString(cb));
			index++;
		}
		body.setBodyList(list);
		iotp.setBody(body);//JSON.toJSONString(body)
		IotpBodyUtils ibu = new IotpBodyUtils();
		IOTPBean iotp2 = new IOTPBean();
		for(byte[] b:ibu.toByteArray(iotp)){
			System.out.println(Arrays.toString(b));
			Code code = ibu.toIotpBean(b);
			if("0".equals(code.getCode())){
				System.out.println("dasdasdas   "+code.getCode());
				System.out.println(code.getMessage());
				System.out.println(ibu.getIotpBean().toString());
			}else{
				System.out.println(code.getCode());
				System.out.println(code.getMessage());
			}
		}
//		IOTPBean iotpb = ibu.getIotpBean();
//		IOTPBody iotpy = iotpb.getBody();
//		List<String> listmsg = iotpy.getBodyList();
//		String msgbody = listmsg.get(1000);
//		System.out.println(msgbody);
//		CollectionAgentConfig msg11 = JSON.parseObject(msgbody, CollectionAgentConfig.class);
//		System.out.println(msg11.toString());
	}
}
